﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WISD.CarFriend.BLL.OA;

namespace WISD.CarFriend.Web.Admin.OA.MemberCardTypeManage
{
    public partial class CardConsumeItemEdit : Utility.BasicPage
    {
        #region 字段
        private CardConsumeItemModule m_CardConsumeItemModuleBLL = new CardConsumeItemModule();
        private int m_MemberCardTypeId;
        private int m_CardConsumeItemId;
        #endregion


        #region 属性
        /// <summary>
        /// 会员卡类型编号
        /// </summary>
        public int MemberCardTypeId
        {
            get { return m_MemberCardTypeId; }
            set { m_MemberCardTypeId = value; }
        }
        #endregion


        #region 方法
        /// <summary>
        /// Page_Load
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request.QueryString["id"] == null || !int.TryParse(Request.QueryString["id"], out this.m_CardConsumeItemId) ||
                    Request.QueryString["memberCardTypeId"] == null || !int.TryParse(Request.QueryString["memberCardTypeId"], out this.m_MemberCardTypeId))
                {
                    base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                    return;
                }

                if (!IsPostBack)
                {
                    // 验证权限
                    base.CheckPermission("CardConsumeItemManage_Add");

                    WISD.CarFriend.Model.CFModel.T_CF_OA_CardConsumeItem cardConsumeItemModel
                        = this.m_CardConsumeItemModuleBLL.GetModel(this.m_CardConsumeItemId);
                    if (cardConsumeItemModel != null)
                    {
                        this.txtConsumeItem.Text = cardConsumeItemModel.ConsumeItem;
                        this.txtConsumeCount.Text = cardConsumeItemModel.ConsumeCount.ToString();
                        this.ddlFix.SelectedValue = cardConsumeItemModel.Memo1 == "1" ? "1" : "0";
                        FCKeditor.Value = cardConsumeItemModel.Memo;
                    }
                    else
                    {
                        base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                    }
                }
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }


        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                WISD.CarFriend.Model.CFModel.T_CF_OA_CardConsumeItem cardConsumeItemModel
                    = this.m_CardConsumeItemModuleBLL.GetModel(this.m_CardConsumeItemId);
                cardConsumeItemModel.ConsumeItem = this.txtConsumeItem.Text.Trim();
                cardConsumeItemModel.ConsumeCount = int.Parse(this.txtConsumeCount.Text.Trim());
                cardConsumeItemModel.Memo1 = this.ddlFix.SelectedValue.ToString();
                cardConsumeItemModel.Reviser = Session["UserCode"].ToString();
                cardConsumeItemModel.ReviseDate = DateTime.Now;
                cardConsumeItemModel.Memo = FCKeditor.Value.ToString().Trim();
                this.m_CardConsumeItemModuleBLL.Update(cardConsumeItemModel);
                ShowMessageBox("修改成功！", "CardConsumeItemList.aspx?id=" + this.m_MemberCardTypeId.ToString(), "Success");
            }
            catch (Exception exception)
            {
                base.ShowMessageBox(350, 230, "错误提示", "<b>出现错误啦！</b>" + exception.Message.ToString(), "back", "Error");
            }
        }
        #endregion


    }
}